package threads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Service {

	 static Account account=new Account();
	 public static void main(String[] args) {
		 ExecutorService executor=Executors.newCachedThreadPool();
		 executor.execute(new Task1());
		 executor.execute(new Task2());
		
	 }
	 
	 
	private static class Task1 implements Runnable{

		@Override
		public void run() {
		    
			account.testMethod(new String());
		}
		 
	 }
	 private static class Task2 implements Runnable{

			@Override
			public void run() {
			    
				account.synNotifyMethod(new String());
			}
			 
		 }
 
   }
  

 class Account{
	   public void testMethod(Object lock) {
	        try {
	            synchronized (lock) {
	                System.out.println("begin wait() ThreadName="
	                        + Thread.currentThread().getName());
	                lock.wait();
	                System.out.println("  end wait() ThreadName="
	                        + Thread.currentThread().getName());
	            }
	        } catch (InterruptedException e) {
	            e.printStackTrace();
	        }
	    }

	    public void synNotifyMethod(Object lock) {
	        try {
	            synchronized (lock) {
	                System.out.println("begin notify() ThreadName="
	                        + Thread.currentThread().getName() + " time="
	                        + System.currentTimeMillis());
	                lock.notify();
	                Thread.sleep(5000);
	                System.out.println("  end notify() ThreadName="
	                        + Thread.currentThread().getName() + " time="
	                        + System.currentTimeMillis());
	            }
	        } catch (InterruptedException e) {
	            e.printStackTrace();
	           }
	       }
}